#include "vtkMRMLImageDisplayNode.h"
#include <vtkImageResample.h>
#include <vtkImageMagnify.h>
#include "vtkImageFilterUsingOpenCV.h"
vtkStandardNewMacro(vtkMRMLImageDisplayNode);
vtkCxxRevisionMacro(vtkMRMLImageDisplayNode, "$Revision: 1.0 $");
vtkMRMLImageDisplayNode::vtkMRMLImageDisplayNode(void)
{
	ImageData = NULL;
	OutImageData = NULL;
	IsBuildPipeline = 0;
}

vtkMRMLImageDisplayNode::~vtkMRMLImageDisplayNode(void)
{
	SetImageData(NULL);
	SetOutImageData(NULL);
}

vtkMRMLNode* vtkMRMLImageDisplayNode::CreateNodeInstance()
{
	vtkObject* ret = vtkObjectFactory::CreateInstance("vtkMRMLImageDisplayNode");
	if(ret)
	{
		return (vtkMRMLImageDisplayNode*)ret;
	}
	// If the factory was unable to create the object, then create it here.
	return new vtkMRMLImageDisplayNode;
}

const char* vtkMRMLImageDisplayNode::GetNodeTagName()
{
	return "ImageDisplayNode";
}

 vtkImageData* vtkMRMLImageDisplayNode::GetImageData()
 {
	// if (!IsBuildPipeline)
	// {
		BuildPipeline();
	// }
	return GetOutImageData();
 }
 void vtkMRMLImageDisplayNode::UpdateImageDataPipeline()
 {

 }
 void vtkMRMLImageDisplayNode::BuildPipeline(void)
 {
	 vtkImageResample  * imageReSample = vtkImageResample ::New();
	 vtkImageFilterUsingOpenCV * openCVFilter = vtkImageFilterUsingOpenCV::New();
	 imageReSample->SetInput (ImageData);
	 imageReSample->SetAxisMagnificationFactor(0, 0.5);
	 imageReSample->SetAxisMagnificationFactor(1, 0.5);
	 openCVFilter->SetInput(imageReSample->GetOutput());
	 SetOutImageData(openCVFilter->GetOutput());
	 imageReSample->Delete();
	 openCVFilter->Delete();
	 IsBuildPipeline = 1;
 }
